import {NgModule, Optional, SkipSelf} from '@angular/core';
import {HttpModule, XHRBackend, RequestOptions, Http} from "@angular/http";
import {HttpIntercept} from "@core/http/HttpIntercept";
import {AuthService} from "@shared/service/auth/auth.service";
import {EventsService} from "@core/events/events.service";
import {AuthGuardService} from "@shared/service/auth-guard/auth-guard.service";
import {HttpService} from "@core/http/http.service";
import {StatisticsBaiduService} from "@core/statistics/baidu/statistics-baidu.service";
import {SeoModule} from "@core/seo/seo.module";
import {SeoConfig} from "@core/seo/seo-config.modal";
import {WechatShareModule} from "@core/wechat-share/wechat-share.module";
import { WechatShareConfig } from "../interface/wechat-share/wechat-share.model";
import {environment} from "@environments/environment";


export function httpFactory(backend: XHRBackend, defaultOptions: RequestOptions, auth: AuthService, events: EventsService) {
  return new HttpIntercept(backend, defaultOptions, auth, events);
}
export class CustomSeoConfig {
  title: string;
  keywords: string;
  description: string;
}

const CUSTOM_SEO_CONFIG: CustomSeoConfig = {
    title: '体育服务交易平台',
    keywords: '体育新闻,体育视频,体育赞助,体育赛事,体育招商,体育培训',
    description: `求苗体育聚集各类体育产业IP，包含但不限于体育赛事、体育培训、体育旅游、体育赞助、体育用品等各大板块，实现多种资源的聚合与互通, 赛事运营管理、合作机构对接、消费数据统计及线上推广等多服务轻松一键搞定的健康运动服务的互联网平台。`
};
const SEO_CONFIG: SeoConfig = {
  useTitleSuffix: true,
  defaults: {
    titleSuffix: '_求苗体育',
  }
};

const WECHAT_SHARE_CONFIG: WechatShareConfig = {
  debug: false,
  jsSrc: 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js',
  jsApiList: [
    'onMenuShareTimeline',
    'onMenuShareAppMessage',
    'onMenuShareQQ',
    'onMenuShareQZone'
  ],
  defaults: {
    title: '求苗体育',
    desc: '我在求苗上发现一个有意思的活动，快来看看吧！',
    imgSrc: `${environment.ENV_HOST}/assets/icon/logo.png` ,
  }
};

@NgModule({
  imports: [
    HttpModule,
    SeoModule.forRoot(SEO_CONFIG),
    WechatShareModule.forRoot(WECHAT_SHARE_CONFIG)
  ],
  providers: [
    HttpService,
    {
      provide: Http,
      useFactory: httpFactory,
      deps: [XHRBackend, RequestOptions, AuthService, EventsService]
    },
    AuthService,
    AuthGuardService,
    EventsService,
    StatisticsBaiduService
  ]
})

export class CoreModule {
  constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
    if (parentModule) {
      throw new Error(
        'CoreModule is already loaded. Import it in the AppModule only');
    }
  }
}




